﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LAVAA.DAL;
using LAVAA.BL;
using LAVAA.BL.Control;

namespace TestLavaa
{
    [TestClass]
    public class BLTest
    {
        private static LAVAA.UTILS.Logger _logger = new LAVAA.UTILS.Logger(typeof(BLTest));
        [TestMethod]
        public void TestBL()
        {
            try
            {
                int nolla = 0;
                int i = 1 / nolla;
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            _logger.Debug("nu så....");
            UserCase01 userStory = new UserCase01();
            userStory.AddActivity(new Activity()
            {
                Date = DateTime.Now,
                DurationInMinutes = 30,
                Comment = "Denna var vääldigt jobbig..."
            }, FindActivityType("Gå").Id,
            FindUser("Andreas").Id);

            var tst = userStory.FindActivitiesByTypeName("Gå");

            Assert.AreEqual(1, tst.Count());
        }


        private ActivityType FindActivityType(string name)
        {
            LavaaEntitiesConnection context = new LavaaEntitiesConnection();
            return context.ActivityTypes.First(a => a.Name.Contains(name));
        }

        private User FindUser(string firstName)
        {
            LavaaEntitiesConnection context = new LavaaEntitiesConnection();
            var user = context.Users.First(a => a.FirstName.Contains(firstName));
            return user;
        }
    }
}
